000100******************************************************************
000200*PROGRAM : Instructor inquiry                                    *
000300*AUTHOR  : H. James Vo                                           *
000400******************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. INST-I.

      *-----------------------------------------------------------------
000700 ENVIRONMENT DIVISION.
000800     SELECT INFILE   ASSIGN TO "INSTMST.DAT"
000900                     ORGANIZATION    IS  INDEXED
001000                     ACCESS          IS  DYNAMIC
001100                     RECORD KEY      IS  IN-INST-ID
                           ALTERNATE RECORD KEY IS IN-INST-NAME
                               WITH DUPLICATES
001200                     FILE STATUS     IS  WS-STAT.
      *-----------------------------------------------------------------
001300 DATA DIVISION.
001400 FILE SECTION.
001500 FD  INFILE.
001600 01  IN-REC.
           03  IN-INST-ID          PIC 9(3).
001700     03  IN-INST-NAME        PIC X(20).
           03  IN-INST-A           PIC X.

002100 WORKING-STORAGE SECTION.
002200 01  WS-VARS.
002300     03  WS-DATE.
002400         05  WS-YEAR         PIC 99.
002500         05  WS-MONTH        PIC 99.
002600         05  WS-DAY          PIC 99.
002700     03  WS-INST-ID          PIC 9(3).
002800     03  WS-STAT             PIC X(2).
002900     03  WS-CONTINUE         PIC X.
003000     03  WS-EOF              PIC X.
003100     03  WS-LOOP-CNT         PIC 99  VALUE ZEROS.
003200     03  WS-CNT              PIC 999 VALUE ZEROS.
003300 01  OUT-ARRAY.
003400     03  OUT-RECORDS OCCURS 20 TIMES.
003500         05  OUT-NO          PIC 9(3).
003600         05  FILLER          PIC X VALUE SPACES.
               05  OUT-INST-ID     PIC 9(3).
003600         05  FILLER          PIC X VALUE SPACES.
003700         05  OUT-INST-NAME   PIC X(20).
               05  FILLER          PIC X VALUE SPACES.
               05  OUT-INST-A      PIC X.

004400 SCREEN SECTION.
004500 01  ENTER-SCRN.
004600     03  BLANK SCREEN.
004700     03  MENU.
004800         05  LINE 1  COL 01  VALUE "INSTRUCTOR".
004900         05          COL 73  PIC 9(2) FROM WS-MONTH.
005000         05          COL 75  VALUE "/".
005100         05          COL 76  PIC 9(2) FROM WS-DAY.
005200         05          COL 78  VALUE "/".
005300         05          COL 79  PIC 9(2) FROM WS-YEAR.
005400         05  LINE 2  COL 35  VALUE "INSTRUCTOR INQUIRY".
005500         05  LINE 4  COL 29  VALUE "INSTRUCTOR ID".
005600         05          COL 43  PIC 9(3) TO WS-INST-ID AUTO.
               05  LINE 6  COL 29  VALUE "(ENTER 000 TO EXIT)".

005700 01  DISPLAY-SCRN.
005800     03  BLANK SCREEN.
005900     03  DISPLAY-REC.
006000         05  LINE 1  COL 01  VALUE "INSTRUCTOR".
006100         05          COL 73  PIC 9(2) FROM WS-MONTH.
006200         05          COL 75  VALUE "/".
006300         05          COL 76  PIC 9(2) FROM WS-DAY.
006400         05          COL 78  VALUE "/".
006500         05          COL 79  PIC 9(2) FROM WS-YEAR.
006600         05  LINE 2  COL 34  VALUE "INSTRUCTOR INQUIRY".
006700         05  LINE 4  COL 4   PIC X(30) FROM  OUT-RECORDS(1).
006800         05  LINE 5  COL 4   PIC X(30) FROM  OUT-RECORDS(2).
006900         05  LINE 6  COL 4   PIC X(30) FROM  OUT-RECORDS(3).
007000         05  LINE 7  COL 4   PIC X(30) FROM  OUT-RECORDS(4).
007100         05  LINE 8  COL 4   PIC X(30) FROM  OUT-RECORDS(5).
007200         05  LINE 9  COL 4   PIC X(30) FROM  OUT-RECORDS(6).
007300         05  LINE 10 COL 4   PIC X(30) FROM  OUT-RECORDS(7).
007400         05  LINE 11 COL 4   PIC X(30) FROM  OUT-RECORDS(8).
007500         05  LINE 12 COL 4   PIC X(30) FROM  OUT-RECORDS(9).
007600         05  LINE 13 COL 4   PIC X(30) FROM  OUT-RECORDS(10).
007700         05  LINE 14 COL 4   PIC X(30) FROM  OUT-RECORDS(11).
007800         05  LINE 15 COL 4   PIC X(30) FROM  OUT-RECORDS(12).
007900         05  LINE 16 COL 4   PIC X(30) FROM  OUT-RECORDS(13).
008000         05  LINE 17 COL 4   PIC X(30) FROM  OUT-RECORDS(14).
008100         05  LINE 18 COL 4   PIC X(30) FROM  OUT-RECORDS(15).
008200         05  LINE 19 COL 4   PIC X(30) FROM  OUT-RECORDS(16).
008300         05  LINE 20 COL 4   PIC X(30) FROM  OUT-RECORDS(17).
008400         05  LINE 21 COL 4   PIC X(30) FROM  OUT-RECORDS(18).
008500         05  LINE 22 COL 4   PIC X(30) FROM  OUT-RECORDS(19).
008600         05  LINE 23 COL 4   PIC X(30) FROM  OUT-RECORDS(20).
008700         05  LINE 25 COL 18  VALUE "PRESS ENTER TO CONTINUE, OR 'X
008800-                                  "' TO EXIT".
008900         05          COL 58  PIC X   TO  WS-CONTINUE AUTO.
009000
009100 01  DISPLAY-EOF-SCRN.
009200     03  BLANK SCREEN.
009300     03  DISPLAY-REC.
006000         05  LINE 1  COL 01  VALUE "INSTRUCTOR".
006100         05          COL 73  PIC 9(2) FROM WS-MONTH.
006200         05          COL 75  VALUE "/".
006300         05          COL 76  PIC 9(2) FROM WS-DAY.
006400         05          COL 78  VALUE "/".
006500         05          COL 79  PIC 9(2) FROM WS-YEAR.
006600         05  LINE 2  COL 34  VALUE "INSTRUCTOR INQUIRY".
006700         05  LINE 4  COL 4   PIC X(30) FROM  OUT-RECORDS(1).
006800         05  LINE 5  COL 4   PIC X(30) FROM  OUT-RECORDS(2).
006900         05  LINE 6  COL 4   PIC X(30) FROM  OUT-RECORDS(3).
007000         05  LINE 7  COL 4   PIC X(30) FROM  OUT-RECORDS(4).
007100         05  LINE 8  COL 4   PIC X(30) FROM  OUT-RECORDS(5).
007200         05  LINE 9  COL 4   PIC X(30) FROM  OUT-RECORDS(6).
007300         05  LINE 10 COL 4   PIC X(30) FROM  OUT-RECORDS(7).
007400         05  LINE 11 COL 4   PIC X(30) FROM  OUT-RECORDS(8).
007500         05  LINE 12 COL 4   PIC X(30) FROM  OUT-RECORDS(9).
007600         05  LINE 13 COL 4   PIC X(30) FROM  OUT-RECORDS(10).
007700         05  LINE 14 COL 4   PIC X(30) FROM  OUT-RECORDS(11).
007800         05  LINE 15 COL 4   PIC X(30) FROM  OUT-RECORDS(12).
007900         05  LINE 16 COL 4   PIC X(30) FROM  OUT-RECORDS(13).
008000         05  LINE 17 COL 4   PIC X(30) FROM  OUT-RECORDS(14).
008100         05  LINE 18 COL 4   PIC X(30) FROM  OUT-RECORDS(15).
008200         05  LINE 19 COL 4   PIC X(30) FROM  OUT-RECORDS(16).
008300         05  LINE 20 COL 4   PIC X(30) FROM  OUT-RECORDS(17).
008400         05  LINE 21 COL 4   PIC X(30) FROM  OUT-RECORDS(18).
008500         05  LINE 22 COL 4   PIC X(30) FROM  OUT-RECORDS(19).
008600         05  LINE 23 COL 4   PIC X(30) FROM  OUT-RECORDS(20).
012100         05  LINE 25 COL 18  VALUE "END OF FILE, PRESS ENTER TO CO
012200-                                  "NTINUE".
012300         05          COL 58  PIC X   TO  WS-CONTINUE AUTO.

012400*-----------------------------------------------------------------
012500 PROCEDURE DIVISION.
012600 100-MAIN.
012700     ACCEPT WS-DATE FROM DATE
012800     OPEN INPUT INFILE
012900     DISPLAY ENTER-SCRN
013000     ACCEPT  ENTER-SCRN
013200     PERFORM UNTIL WS-INST-ID = ZEROS
013300         MOVE 'N' TO WS-EOF
013100         MOVE WS-INST-ID TO IN-INST-ID
013400         MOVE 1 TO WS-CNT
013500         MOVE SPACES TO WS-CONTINUE
013600         START INFILE KEY >= IN-INST-ID
013700         END-START
013800         PERFORM 200-DISPLAY
013900         DISPLAY ENTER-SCRN
014000         ACCEPT  ENTER-SCRN
014100         MOVE    WS-INST-ID TO IN-INST-ID
014200     END-PERFORM
014300     CLOSE INFILE
014400
014500     EXIT PROGRAM.
014600
014700 200-DISPLAY.
014800     PERFORM UNTIL ((WS-EOF = "Y") OR
014900     ((WS-CONTINUE = "X" OR WS-CONTINUE = "x") AND WS-EOF = "N"))
015000         PERFORM 300-INIT-ARRAY
015100         PERFORM 400-READ-INPUT
015200         IF WS-EOF = "Y"
015300             DISPLAY DISPLAY-EOF-SCRN
015400             ACCEPT DISPLAY-EOF-SCRN
015500         ELSE
015600             DISPLAY DISPLAY-SCRN
015700             ACCEPT DISPLAY-SCRN
015800         END-IF
015900     END-PERFORM.
016000
016100 300-INIT-ARRAY.
016200     MOVE 1 TO WS-LOOP-CNT
016300     PERFORM UNTIL WS-LOOP-CNT > 20
016400         MOVE SPACES TO OUT-RECORDS(WS-LOOP-CNT)
016500         ADD 1 TO WS-LOOP-CNT
016600     END-PERFORM.
016700
016800 400-READ-INPUT.
016900     READ INFILE NEXT RECORD
017000         AT END MOVE 'Y' TO WS-EOF
017100     END-READ
017200     MOVE 1 TO WS-LOOP-CNT
017300     PERFORM UNTIL WS-LOOP-CNT > 20 OR WS-EOF = "Y"
017400         MOVE WS-CNT         TO OUT-NO(WS-LOOP-CNT)
               MOVE IN-INST-ID     TO OUT-INST-ID(WS-LOOP-CNT)
017500         MOVE IN-INST-NAME   TO OUT-INST-NAME(WS-LOOP-CNT)
               MOVE IN-INST-A      TO OUT-INST-A(WS-LOOP-CNT)
017900         READ INFILE NEXT RECORD
018000             AT END MOVE 'Y' TO WS-EOF
018100         END-READ
018200         ADD 1 TO WS-LOOP-CNT
018300         IF WS-CNT = 999
018400             MOVE 1 TO WS-CNT
018500         ELSE
018600             ADD 1 TO WS-CNT
018700         END-IF
018800     END-PERFORM.
018900
